<template>
	<view>
		<view style='padding:10px 15px;background-color: white;border-bottom: 1px #F0F0F0 solid;'>
			<u-search placeholder="请输入查询条件" v-model="keyword" shape="round" :showAction="true" actionText="搜索"
				:animation="false" height='60' style='width:100%' @focus='focusSearch'></u-search>
		</view>
		<view class="planAudit">
			<!-- 	<k-scroll-view ref="k-scroll-view" @onPullDown="handlePullDown" :emptyTip="emptyTip" :bottom="bottom"
				:autoPullUp="true" @onPullUp="handleLoadMore"> -->
			<view style="border-top: 1px #E7E7E7 solid;padding: 0 0 0 20px;">
				<u-tabs :list="list1" @click='recordClick' lineWidth="40" lineHeight="6" lineColor="#108EEF"
					:current='currentIndex' :activeStyle="{
				    color: '#303133',
				    fontWeight: 'bold',
				    transform: 'scale(1.05)'
				}"></u-tabs>
			</view>
			<view class="planAudit_project" v-for="(item,index) in checkTask">
				<view>
					<view @click="viewDetails(item.id)">
						<view class="planAudit_project_title">
							<image class='planAudit_project_img' src="/static/dailySupervision/tjbg.png" alt=""></image>
								<text>{{item.ownerName}}</text>
						</view>
						<view class="planAudit_project_content" style="width: 40%;">
							<text class='planAudit_project_text'>询查日期</text>
							<text class='planAudit_project_text'>询查人员</text>
							<text class='planAudit_project_text'>当前节点</text>
						</view>
						<view class="planAudit_project_content" style="width: 60%;">
							<text class='planAudit_project_text'>{{item.patrolTime}}</text>
							<text class='planAudit_project_text'>{{item.perName}}</text>
							<text
								class="planAudit_project_text">{{item.patrolStatus==1?'询查中':item.patrolStatus==2?'已询查':item.patrolStatus==3?'整改通知审核中':item.patrolStatus==4?'整改中':item.patrolStatus==5?'已整改':item.patrolStatus==6?'待完结':'已完结'}}</text>
						</view>
					</view>
					<view class="" style="width: 100%;text-align: left;" v-if="button">
						<text type="primary" class="add" @click="clickEdit(item.id)"
							v-if="item.patrolStatus==2&&tabsIndex==1  ||tabsIndex==0 ">修改</text>
						<text type="primary" class="add" style="width: 35%;"
							v-if="item.patrolStatus==2&&tabsIndex==1 ||tabsIndex==0"
							@click="clickRemove(item)">{{tabsIndex==0?'取消':tabsIndex==1&&item.isRisks==1&&item.patrolStatus == 2?'下发整改通知':'完结'}}</text>
						<text type="primary" class="add" style="width: 35%;" v-if="item.patrolStatus==5&&tabsIndex==1"
							@click="clickRemove(item)">整改反馈审核</text>
						<text type="primary" class="add" v-if="item.patrolStatus==6&&tabsIndex==1"
							@click="clickRemove(item)">完结</text>
					</view>
				</view>

			</view>
			<!-- </k-scroll-view> -->
		</view>
	</view>
</template>

<script>
	import * as api from '@/common/api/supervision.js'
	import kScrollView from '@/components/k-scroll-view/k-scroll-view.vue';
	export default {
		components: {
			kScrollView
		},
		data() {
			return {
				keyword: "",
				list1: [{
					name: '询查中',
				}, {
					name: '已询查',
				}, {
					name: '已完结',
				}],
				num: 1,
				tabsIndex: 0,
				options: {},
				checkTask: [],
				page: {
					"current": 1,
					"size": 10
				},
				pages: '',
				showTotal: true,
				text: "取消",
				button: true,
				currentIndex: 0,
				numData: 1

			}
		},
		mounted() {
			if (!this.options.index) {
				this.search([1])
			}
		},
		onLoad(option) {
			if (option.index) {
				this.currentIndex = option.index
				this.tabsIndex = option.index
				if (option.index == 0) {
					let num = [1]
					this.currentIndex = 0
					this.search(num, 'tab')
				}
				if (option.index == 1) {
					let num = [2, 4, 5, 6]
					this.currentIndex = 1
					this.search(num, 'tab')
				}
				this.options = option
			} else {
				if (!Object.keys(option).length == 0) {
					this.options = JSON.parse(option.formSearch)
				}
			}

		},
		methods: {
			search(index, type) {
				let fromData;
				if (this.options.patrolStatusList && !type) {
					if (this.options.patrolStatusList.length == 0) {
						this.options.patrolStatusList = [1]
						this.currentIndex = 0
						fromData = {
							...this.options,
							...this.page,

						}
					} else {
						fromData = {
							...this.options,
							...this.page,
						}
					}
					if (this.options.patrolStatusList[0] == 1) {
						this.currentIndex = 0
					} else if (this.options.patrolStatusList[0] == 7) {
						this.button = false
						this.currentIndex = 2
					} else {
						this.currentIndex = 1
					}
				} else {
					delete this.options.patrolStatusList
					fromData = {
						...this.options,
						...this.page,
						'patrolStatusList': index

					}
				}
				api.default.getList(fromData).then(res => {
					this.checkTask = res.data.data.records
					this.pages = res.data.data.pages
					this.pageSize = res.data.data.size
					this.total = res.data.data.total
				})
			},

			// tab切换
			recordClick(itme) {
				this.tabsIndex = itme.index
				if (itme.index == 0) {
					this.search([1], 'tab')
					this.text = '取消'
					this.button = true
				} else if (itme.index == 1) {
					let num = [2, 4, 5, 6]
					this.search(num, 'tab')
					this.text = '完结'
					this.button = true

				} else {
					this.search([7], 'tab')
					this.button = false
				}

			},
			// 搜索条件
			focusSearch() {
				this.$goBack('./search', 2);
			},

			// 修改
			clickEdit(id) {
				this.$goBack('./InspectionRecord?type=edit&Sid=' + id + '&inspStatus=' + this.tabsIndex, 2);
			},

			viewDetails(id) {
				// if (this.tabsIndex == 2) {
				this.$goBack('./InspectionRecord?type=view&Sid=' + id + '&inspStatus=' + this.tabsIndex, 2);
				// }
			},

			onReachBottom() {
				this.numData += 1
				if (this.numData <= this.pages) {
					// if (this.options.patrolStatusList) {
					// 	api.default.getList({
					// 		"current": this.numData,
					// 		"size": 10,
					// 		...this.options
					// 	}).then(res => {
					// 		this.checkTask = this.checkTask.concat(res.data.data.records);
					// 	})
					// }

					if (this.tabsIndex == 0) {
						api.default.getList({
							"current": this.numData,
							"size": 10,
							'patrolStatusList': [1]
						}).then(res => {
							this.checkTask = this.checkTask.concat(res.data.data.records);
						})
					}

					if (this.tabsIndex == 1) {
						api.default.getList({
							"current": this.numData,
							"size": 10,
							'patrolStatusList': [2, 4, 5, 6]
						}).then(res => {
							this.checkTask = this.checkTask.concat(res.data.data.records);
						})
					}

					if (this.tabsIndex == 2) {
						api.default.getList({
							"current": this.numData,
							"size": 10,
							'patrolStatusList': [7]
						}).then(res => {
							this.checkTask = this.checkTask.concat(res.data.data.records);
						})
					}
				}
			},

			// 下拉刷新
			onPullDownRefresh() {
				this.numData = 1
				if (this.tabsIndex == 0) {
					let num = [1]
					this.search(num, 'tab')
				}
				if (this.tabsIndex == 1) {
					let num = [2, 4, 5, 6]
					this.search(num, 'tab')
				}
				if (this.tabsIndex == 2) {
					let num = [7]
					this.search(num, 'tab')
				}
				uni.stopPullDownRefresh(); //停止刷新
			},

			// 删除
			clickRemove(item) {
				var that = this
				let val = ""
				if (this.tabsIndex == 0) {
					val = '取消'

				} else if (this.tabsIndex == 1 && item.patrolStatus == 6) {
					val = '完结'

				}

				// 下发通知
				if (this.tabsIndex == 1 && item.isRisks == 1 && item.patrolStatus == 2) {
					this.$goBack('./rectificationNotice?type=view&Sid=' + item.id + '&inspStatus=' + this
						.tabsIndex, 2)
					return
				}
				// 整改审核
				if (this.tabsIndex == 1 && item.patrolStatus == 5) {
					this.$goBack('./feedbackReview?type=view&Sid=' + item.id + '&inspStatus=' + this.tabsIndex, 2)
					return
				}

				uni.showModal({
					title: '提示',
					content: '确认要' + val + '当前询查记录吗？',
					success: function(res) {
						if (res.confirm) {
							if (that.tabsIndex == 0) {
								api.default.getSupervisionRemove({
									id: item.id
								}).then(res => {
									uni.showToast({
										title: '取消成功！',
										icon: 'success',
										duration: 1000
									})
									setTimeout(function() {
										that.search([2, 4, 5, 6])
										that.currentIndex = 0
										that.tabsIndex = 0
									}, 1000);
								})
							} else {

								api.default.getSupervisionArchive({
									id: item.id
								}).then(res => {
									uni.showToast({
										title: '完结成功！',
										icon: 'success',
										duration: 1000
									})
									setTimeout(function() {
										this.currentIndex = 1
										this.tabsIndex = 1
										that.search([that.tabsIndex + 1])
									}, 1000);
								})

							}
						}
					}
				});
			},

			// // 监听点击右上角事件
			onNavigationBarButtonTap(e) {
				this.$goBack('./InspectionRecord?type=add&inspStatus=' + this.tabsIndex, 2);
			},
		}
	}
</script>

<style lang="scss" scoped>
	.planAudit {
		width: 100%;

		.planAudit_project {
			margin: 20rpx 35rpx;
			background-color: white;
			border-bottom: 1px #F2F2F2 solid;

			.planAudit_project_title {
				width: 100%;
				padding: 5px 0;
				display: inline-block;

				.planAudit_project_img {
					width: 30rpx;
					height: 40rpx;
					margin: 0 25rpx 0 20rpx;
					vertical-align: middle
				}
			}

			.planAudit_project_content {
				display: inline-block;
				// margin: 10px 0;

				.planAudit_project_text {
					width: 100%;
					display: block;
					margin: 20rpx;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis
				}
			}

			.add {
				width: 30%;
				margin: 10px;
				display: inline-block;
				text-align: center;
				padding: 10rpx 8rpx;
				border-radius: 15px;
				background-color: #1590EF;
				color: white;
			}

		}
	}
</style>
